//
//  PWDViewController.m
//  jiyujiaProgram
//
//  Created by 中良 赵 on 15/10/13.
//  Copyright (c) 2015年 中良 赵. All rights reserved.
//

#import "PWDViewController.h"

@interface PWDViewController () <UITextFieldDelegate,UIAlertViewDelegate>

@end

@implementation PWDViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 20, 30, 30)];
    [btn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(backaction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.securityTextField resignFirstResponder];
    [self.userTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)sendCheckCode:(id)sender
{
    [self.securityTextField resignFirstResponder];
    [self.userTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
    
    NSDictionary *param = @{
                            @"mobile":_userTextField.text,
                            @"status":@"1",
                            };
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(CHECKCODE) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            if ([result[@"errCode"] integerValue] == 200) {
                SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
            }else{
                SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
            }
        }
    }];
}

- (IBAction)resetPwd:(id)sender
{
    [self.securityTextField resignFirstResponder];
    [self.userTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
    NSDictionary *param = @{
                            @"mobile":_userTextField.text,
                            @"password":_passwordTextField.text,
                            @"checkCode":_securityTextField.text,
                            @"member_type":[NSString stringWithFormat:@"%ld",_typeSegment.selectedSegmentIndex + 1],
                            };
    UserInfoManager *userInfo = [UserInfoManager sharedUserInfoManager];
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(RESETPWD) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            if ([result[@"errCode"] integerValue] == 200) {
                userInfo.user = self.userTextField.text;
                userInfo.password = self.passwordTextField.text;
                [userInfo saveUserInfoToSanbox];
                SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, self);
            }else{
                SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
            }
        }
    }];
}
-(void)backaction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}


@end
